<template>
	<view class="page-box">
		<uni-section title="基本信息" type="line"></uni-section>
		<view class="form-box">
			<view><view>小区名称</view><text>{{house.community_name}}</text></view>
			<view><view>具体位置</view><text>{{house.specific_location}}</text></view>
			<view><view>房屋户型</view><text>{{house.house_layout}}</text></view>
			<view><view>房屋面积</view><text>{{house.house_area}} ㎡</text></view>
			<view><view>户型结构</view><text>{{house.house_layout_structure}}</text></view>
			<view><view>装修情况</view><text>{{house.house_renovation_condition}}</text></view>
			<view><view>房屋朝向</view><text>{{house.orientation_of_house}}</text></view>
			<view><view>配备电梯</view><text>{{house.is_equipped_with_elevator}}</text></view>
			<view><view>房屋楼层</view><text>{{house.house_floor}}</text></view>
			<view><view>房本年限</view><text>{{house.period_of_house}}</text></view>
			<view><view>建筑年代</view><text>{{house.age_of_architecture}} 年</text></view>
			<view><view>房屋类型</view><text>{{house.type_of_residence}}</text></view>
			<view><view>抵押情况</view><text>{{house.condition_of_mortgage}}</text></view>
		</view>
		<uni-section title="照片信息" type="line"></uni-section>
		<view class="img-box">
			<view v-for="(item, index) in house.img_url">
				<image :src="item" mode="aspectFill"></image>
			</view>	
		</view>
		<uni-section title="销售信息" type="line"></uni-section>
		<view class="form-box sale-box">
			<view><view>房屋售价</view><text>{{house.house_price}} 万元</text></view>
			<view>
				<view>分佣比例</view>
				<view class="rate-box">
					<text>买方佣金 {{house.saler_ratio}} %</text>
					<text>卖方佣金 {{house.seller_ratio}} %</text>
				</view>
			</view>
		</view>
		<view class="two-btn">
			<view class="btn-box" @click="fnBtn(true)">通过</view>
			<view class="btn-box" @click="fnBtn(false)">拒绝</view>
		</view>
	</view>
</template>

<script>
import store from '@/store/store.vue'
import uniSection from '@/components/uni-section/uni-section.vue';
export default {
	onLoad(options){
		this.house = JSON.parse(options.house)	
		console.log(this.house)
		this.house.house_layout_structure = this.list[0].array[this.house.house_layout_structure].val
		this.house.house_renovation_condition = this.list[1].array[this.house.house_renovation_condition].val
		this.house.orientation_of_house = this.list[2].array[this.house.orientation_of_house].val
		this.house.is_equipped_with_elevator = this.list[3].array[this.house.is_equipped_with_elevator].val
		this.house.period_of_house = this.list[4].array[this.house.period_of_house].val
		this.house.type_of_residence = this.list[5].array[this.house.type_of_residence].val
		this.house.condition_of_mortgage = this.list[6].array[this.house.condition_of_mortgage].val
		let arr = this.house.house_floor.split(';')
		this.house.house_floor = '第 ' + arr[0] + ' 层    共 ' + arr[1] + ' 层'
		arr = this.house.commission_share_ratio.split(';')
		this.house.saler_ratio = arr[0]
		this.house.seller_ratio = arr[1]	
		arr = this.house.img_url.split(';')
		arr.pop()
		for(let j = 0; j < arr.length; j++){
			arr[j] = store.url + '/uploads/' + arr[j]
		}
		this.house.img_url = arr
	},
	components: {
		uniSection
	},
	data() {
		return {			
			house:{},
			list:[					
				{				
					array: [{ val: '平层' }, { val: '复式' }, { val: '错层' }, { val: '跃层' }]
				},
				{				
					array: [{ val: '毛坯' }, { val: '普通装修' }, { val: '精装修' }]
				},
				{
					array: [{ val: '朝南' }, { val: '朝东' }, { val: '朝西' }, { val: '朝北' }]
				},
				{
					array: [{ val: '有电梯' }, { val: '无电梯' }]
				},			
				{			
					array: [{ val: '不满2年' }, { val: '满2年' }, { val: '满5年' }]
				},	
				{
					array: [{ val: '住宅' }, { val: '别墅' }]
				},
				{
					array: [{ val: '无抵押' }, { val: '有抵押' }]
				}
			]
		};
	},
	methods: {
		fnBtn(type) {
			let _this = this
			let url = ''
			uni.request({
			    url: store.url + '/house/verify_house',
				method: 'POST',
			    data: {
					house_source_id: _this.house.house_source_id,
					verify: type,
					user_id: _this.house.user_id
				},
			    header: {
					"content-type": "application/json;charset=utf-8"						
			    },
			    success: (res) => {					
					if(type == true){
						url = '/pages/house/state?param=' + encodeURIComponent(JSON.stringify(1))				        
					}else{
						url = '/pages/house/state?param=' + encodeURIComponent(JSON.stringify(2))				        
					}					
					uni.navigateTo({
						url: url
					})							
			    },
				fail: (res)=>{		
					uni.showModal({
					    title: '提示',
					    content: '访问服务器失败: ' + res.data.message
					});						
				}
			});				
		}
	}
};
</script>

<style lang="scss" scoped>
.page-box {
	padding-bottom: 88rpx;
	box-sizing: border-box;

	/deep/ .uni-section {
		margin-top: 0;
		background: #fff;
	}

	/deep/ .line {
		background-color: #f13b32;
	}
}

.form-box {
	margin-bottom: 20rpx;
	padding-left: 40rpx;
	box-sizing: border-box;
	background: #fff;

	> view {
		display: flex;
		border-bottom: 1px solid #e5e5e5;
		box-sizing: border-box;
		align-items: center;
		font-size: 24rpx;

		&:last-of-type {
			border-bottom: none;
		}

		view {
			width: 140rpx;
			line-height: 80rpx;
			font-size: 24rpx;
		}
		
		text {
			padding: 25rpx 0;
			line-height: 30rpx;
			flex: 1;
		}
	}
}

.sale-box > view {
	align-items: flex-start;
}

.sale-box .rate-box {
	flex: 1;
	
	text {
		display: block;
		border-bottom: 1px solid #e5e5e5;
		
		&:last-of-type {
			border-bottom: none;
		}
	}
}

.img-box {
	margin-bottom: 20rpx;
	padding: 20rpx 20rpx;
	box-sizing: border-box;
	overflow: hidden;
	background: #fff;

	view {
		float: left;
		margin: 10rpx 20rpx;
		width: calc((100vw - 160rpx) / 3);
		height: calc((100vw - 160rpx) / 3);
	}
	
	image {
		display: block;
		width: 100%;
		height: 100%;
	}
}

.two-btn {
	display: flex;
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
	text-align: center;
	color: #fff;
	background: #f13b32;
	
	.btn-box {
		position: relative;
		flex: 1;
		line-height: 88rpx;
		
		&::after {
			position: absolute;
			content: '';
			width: 1px;
			top: 25%;
			right: 0;
			height: 50%;
			background: #FFF;
		}
		
		&:last-of-type::after {
			width: 0;
		}
	}
}
</style>
